﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace OfficeDocumentsGenerator
{
    /// <summary>
    /// Interaction logic for ProgressWindow.xaml
    /// </summary>
    public partial class ProgressWindow : Window
    {
        private BackgroundWorker statusChecker;

        public ProgressWindow()
        {
            InitializeComponent();
            statusChecker = new BackgroundWorker();
            statusChecker.WorkerReportsProgress = true;
            statusChecker.WorkerSupportsCancellation = true;
            statusChecker.DoWork += statusChecker_DoWork;

            statusChecker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                progressBar.Value = args.ProgressPercentage;
                labelProgress.Content = TestParent.ProgressPercentage;
                if (args.ProgressPercentage == 100)
                {
                    this.Close();
                }
            };
            statusChecker.RunWorkerAsync();
        }
        void statusChecker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                Thread.Sleep(50);
                statusChecker.ReportProgress(TestParent.ProgressPercentage);
            }
        }
    }
}
